<?php
//Get Project Info
$project = $projects->row();
?>
<div id="loading-image" style="display: none">
    <img src="<?php echo image_url('loading.gif') ?>"/>
</div>
<form id="form-bid" method="POST">
    <div id="error-bid" class="col-lg-12 col-sm-12 col-md-12 col-xs-12" style="margin-left:10px;"></div>
    <div class="col-lg-10 col-md-10 col-sm-10 left-bid no-padding-left">
        <div class="col-lg-4 col-md-12 col-sm-12">
            <div class="col-lg-12 col-md-12 col-sm-12 x8-16-b no-padding-left"><?php echo $this->lang->line('Bid') ?>:
            </div>
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding-left">
                <div
                    class="col-lg-4 col-sm-4 col-md-4 col-xs-4  no-padding-left x8-16 label-bid"><?php echo $this->lang->line('Your Bid') ?>
                    :
                </div>
                <div class="col-lg-7 col-sm-7 col-md-7 col-xs-7 no-padding-left">
                    <input autocomplete="off" name="bidAmt" type="text" id="bidAmt"
                           value="<?php if (isset($bid->bid_amount)) echo $bid->bid_amount; else echo set_value('bidAmt'); ?>"
                           class="form-control">
                </div>
                <span class="col-lg-1 col-sm-1 col-md-1 col-xs-1 no-padding-left label-bid x8-16">$</span>
            </div>
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding-left">
                <div
                    class="col-lg-5 col-sm-5 col-md-5 col-xs-5 no-padding-left x8-16 label-bid"><?php echo $this->lang->line('Paid to you') ?>
                    :
                </div>
                <div class="col-lg-6 col-sm-6 col-md-6 col-xs-5 no-padding-left x8-16 label-bid" id="bid-receive">
                    0
                </div>
                <input type="hidden" name="bid_paid" id="bid_paid" value="">
                <span class="col-lg-1 col-sm-1 col-md-1 col-xs-1 no-padding-left label-bid x8-16">$</span>
            </div>
        </div>
        <div class="col-lg-4 col-sm-12 col-md-12 col-xs-12">
            <span
                class="col-lg-12 col-sm-12 col-md-12 x8-16-b no-padding-left"><?php echo $this->lang->line('Deliver in') ?>
                :</span>

            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding-left">
                <div class="col-lg-9 col-sm-9 col-md-9 col-xs-9 no-padding-left">
                    <input type="text"
                           value="<?php if (isset($bid->bid_days)) echo $bid->bid_days; else echo set_value('days'); ?>"
                           name="days" class="form-control">
                </div>
                <span
                    class="col-lg-3 col-xs-3 no-padding-left label-bid x8-16"><?php echo $this->lang->line('Days') ?></span>
            </div>
        </div>
        <div class="col-lg-4 col-sm-12 col-md-12 col-xs-12">
            <span
                class="col-lg-12 col-sm-12 col-md-12 x8-16-b no-padding-left"><?php echo $this->lang->line('Milestone Request') ?>
                :</span>

            <div class="col-lg-12 no-padding-left">
                <div class="col-lg-9 col-sm-9 col-md-9 col-xs-9 no-padding-left">
                    <input type="text" name="escrow_flag"
                           value="<?php if (isset($bid->escrow_flag)) echo $bid->escrow_flag; else echo set_value('escrow_flag'); ?>"
                           class="form-control">
                </div>
                <span class="col-lg-3 col-xs-2 no-padding-left label-bid x8-16">$</span>
            </div>
        </div>
    </div>
    <!-- left-bid -->
    <div
        class="col-lg-2 col-sm-12 col-md-12 col-xs-12 margin-top-bottom right-bid no-padding-left no-padding-right">
        <input type="hidden" name="project_id" value="<?php echo $project->id; ?>">
        <button type="submit" value="submit" id="button-bid" name="postBid"
                class="col-lg-12 col-sm-12 col-md-12 col-xs-12 btn btn-primary btn-lg">
            <?php echo $this->lang->line('Place Bid') ?>
        </button>
    </div>
    <!-- right-bid -->
    <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-11">( Lời mời chào không hiển thị cho các freelancer
        khác,chỉ hiển thị cho chủ dự án)
    </div>
    <div class="col-lg-9 margin-top-bottom col-sm-12 col-md-12 col-xs-12">
        <textarea class="form-control" placeholder="Lời chào mới,hãy thuê em đi" name="bid_desc" rows="3"></textarea>
    </div>

    <div class="col-lg-3 col-sm-12 col-md-12 col-xs-12">
        <div class="arrow-feedback col-lg-1 col-sm-1 col-md-1 colxs-1"></div>
        Hãy gửi một lời chào mời thật hấp dẫn, cho họ biết bạn hiểu về dự án thế nào, kỹ năng và kinh nghiệm của bạn
        ra sao, lộ trình hoàn thành sản phẩm...
    </div>
</form>

<script>
    $("#bidAmt").on('input', function () {
        $("#bid-receive").html($("#bidAmt").val() - 5);
        $("#bid_paid").val($("#bidAmt").val() - 5);
    });
    $("#form-bid").validate({
        rules: {
            "bidAmt": {
                required: true,
                digits: true
            },
            "days": {
                required: true,
                digits: true
            },
            "escrow_flag": {
                required: true,
                digits: true
            },
            "bid_desc": {
                required: true
            }
        },
        messages: {
            "bidAmt": {
                required: "<?php echo $this->lang->line('Your Bid')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Your Bid')." ".$this->lang->line('numeric') ?>"
            },
            "days": {
                required: "<?php echo $this->lang->line('Days')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Days')." ".$this->lang->line('numeric') ?>"
            },
            "escrow_flag": {
                required: "<?php echo $this->lang->line('Milestone Request')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Milestone Request')." ".$this->lang->line('numeric') ?>"
            },
            "bid_desc": {
                required: "<?php echo $this->lang->line('Bid desc')." ".$this->lang->line('required') ?>"
            }
        },
        submitHandler: function (form) {
            $.ajax({
                type: "POST",
                url: "<?php echo base_url()."index.php/project/createBid"?>",
                data: $("#form-bid").serializeArray(),
                beforeSend: function () {
                    $('#loading-image').show();
                },
                success: function (data) {
                    $('#loading-image').hide();
                    data = $.parseJSON(data);
                    if (data.status == 'error') {
                        $('#error-bid').html(data.message);
                    } else {
                        $(".bid").load('<?php echo base_url()."index.php/project/editBid"?>', {project_id:<?php echo $project->id?>});
                        $(".num-bid").html(data.num);
                        $('html, body').animate({
                            scrollTop: ($('.list-freelancer-bid').offset().top)
                        }, 500);
                        $(".list-freelancer-bid > table").append('<tr><td><div class="col-lg-7"><a class="thumbnail" href="#"><img class="img-responsive" src="http://placehold.it/400x300"></a></div><div class="col-lg-5 col-sm-5 col-md-5 x8-15-b">' + data.id[0].user_name + '</div></td>' +
                            '<td class="x8-24-b padding-table-freelancer-bid">' + data.id[0].bid_amount +
                            '</td><td class="x8-16 padding-table-freelancer-bid">' + data.id[0].bid_days + ' <?php echo $this->lang->line('Days');?>' + '</td><td class=""><div class="col-lg-12 col-md-12 col-sm-12  reviews"><p class="col-lg-12 col-md-12 col-sm-12 x8-20-b">Khiếu nại</p><p class="col-lg-12 col-md-12 col-sm-12  x8-40-b">0/5</p><div class="col-lg-12 col-md-12 col-sm-12"><input value="0" type="number" data-star-captions="{}" data-default-caption="{rating}" class="rating" min=0 max=5  data-size="xs" ></div><p class="reviews-user xanh-15">( 0 reviews)</p><p class="salary-user"><span class="x8-16">Chi tiêu: </span><span class="x8-20-b">$5324</span></p></div></td></tr>');
                    }
                }
            });
        }
    });
</script>